<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
        
</body>
<script>
    //如果短时间内大量触发同一事件，只会执行一次函数。 防抖
    function debounce(func,wait) {
    let timeout;
    return function () {
        let context = this;
        let args = arguments;
        console.log(args)
        console.log(context)
        if (timeout) clearTimeout(timeout);

        let callNow = !timeout;
        timeout = setTimeout(() => {
            timeout = null;
        }, wait)

        if (callNow) func.apply(context, args)
    }
}
function a(){
    console.log(123)
}
let b=debounce(a,399)
console.log(b)
// 在函数执行一次之后，该函数在指定的时间期限内不再工作 节流
function throttle(func, wait) {
    let timeout;
    return function() {
        let context = this;
        let args = arguments;
        if (!timeout) {
            timeout = setTimeout(() => {
                timeout = null;
                func.apply(context, args)
            }, wait)
        }

    }
}

</script>
</html>